package com.op.teachingliteapp.fragment.resource;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.op.teachingliteapp.R;



public class ResourceGridAdapter extends BaseAdapter{
	private ArrayList<ResourceCellDataProvider>  list;
	 private Context mContext;

	 public ResourceGridAdapter(Context mContext,ArrayList<ResourceCellDataProvider> list) {
	  this.mContext = mContext;
	  this.list=list;
	  list.add(new ResourceCellDataProvider("课程PPT",R.drawable.ppt1));
	  list.add(new ResourceCellDataProvider("上机实验",R.drawable.sjsy1));
	  list.add(new ResourceCellDataProvider("视频资料",R.drawable.spzl1));
	  list.add(new ResourceCellDataProvider("课程案例",R.drawable.kcal1));
	  list.add(new ResourceCellDataProvider("上课计划",R.drawable.kcjh1));
	  list.add(new ResourceCellDataProvider("学生名单",R.drawable.xsmd1));
	 }
	 
		public Context getContext(){
			return mContext;
		}
	
	 @Override
	 public int getCount() {
		 return list.size();
	 }

	 @Override
	 public ResourceCellDataProvider getItem(int position) {
		 return list.get(position);
	 }

	 @Override
	 public long getItemId(int position) {
	  return position;
	 }

	@Override
	 public View getView(final int position, View convertView, ViewGroup parent) {

		LinearLayout gl=null;
		if(convertView!=null){
			gl=(LinearLayout)convertView;
			}else{
				gl=(LinearLayout)LayoutInflater.from(getContext()).inflate(R.layout.item_resource,null);
			}
		final ResourceCellDataProvider data=getItem(position);
		
		
		ImageView img = (ImageView)gl.findViewById(R.id.class_img);
		TextView name_tv = (TextView) gl.findViewById(R.id.class_name);
	  
	  img.setImageResource(data.iconId);
	  name_tv.setText(data.name);
	  
	  return gl;
	 }

}
